# 编写一个反向代理服务器

import flask
from flask import Flask, request, jsonify
import requests

app = Flask(__name__)

clone_target = None

@app.route('/', methods=['POST','GET','PUT','DELETE','PATCH','HEAD'])
def proxy():
    url = request.path
    http_method   = request.method
    headers       = dict(request.headers)
    data          = request.get_data()
    response      = requests.request(http_method, clone_target+url, headers=headers, data=data)
    response_data = response.content
    response_code = response.status_code
    response_headers = dict(response.headers)
    return flask.Response(response_data, response_code, response_headers)

def run_proxy_server():
    print(clone_target)
    app.run(host='0.0.0.0', port=8989, debug=False)